import ComponentConfiguration from "@site/src/pages/components-explorer/_components/ComponentConfiguration";
import ComponentHeader from "@site/src/pages/components-explorer/_components/ComponentHeader";
import ComponentTroubleshooting from "@site/src/pages/components-explorer/_components/ComponentTroubleshooting/index.mdx";

import ComponentMetadata from "./_meta";
import config from "./config.json";

<ComponentHeader meta={ComponentMetadata} />

go2rtc is a free and open source tool for camera streaming, compatible with protocols like RTSP, WebRTC, HomeKit, FFmpeg, and RTMP.
The go2rtc component runs a go2rtc server inside the container and offers a WebRTC proxy for your cameras.

For additional details about go2rtc, visit the projects [GitHub Repository](https://github.com/AlexxIT/go2rtc/)

The go2rtc component provides the following features:

- **WebRTC or MSE**: The component enables you to stream video using WebRTC or MSE (Media Source Extensions), allowing for high resolution, low-latency streaming with audio.
- **Camera proxy**: The component can proxy camera streams, reducing the number of connections per camera.

:::info

Note that without the go2rtc component, the frontend Live page is limited to an MJPEG stream of the frames that Viseron is processing.

:::

## Configuration

The configuration for the go2rtc component is done through the `go2rtc` key in the configuration file.
This config is then passed to the go2rtc server.

For more information about the configuration options available for go2rtc, refer to the [go2rtc documentation](https://github.com/AlexxIT/go2rtc?tab=readme-ov-file#module-streams).

:::warning

It is important to note that the camera names under the `streams` key must match the camera identifiers used in the Viseron configuration.

:::

<details>
  <summary>Configuration example</summary>

```yaml title="/config/config.yaml"
go2rtc:
  streams:
    camera_one:
      - rtsp://user:pass@192.168.XX.X:554/Streaming/Channels/101/
    camera_two:
      - rtsp://user:pass@192.168.XX.X:554/Streaming/Channels/101/

  webrtc:
    candidates:
      - 192.168.XX.X:8555
      - stun:8555

  log:
    level: debug
```

</details>

<ComponentConfiguration meta={ComponentMetadata} config={config} />

## Restreaming

Using go2rtc, you can restream your cameras to Viseron or other services, reducing the number of connections per camera.

<details>
  <summary>Restreaming configuration example</summary>

```yaml title="/config/config.yaml"
ffmpeg:
  camera:
    camera_one:
      name: Camera 1
      host: localhost
      port: 8554
      path: /camera_one

    camera_two:
      name: Camera 2
      host: localhost
      port: 8554
      path: /camera_two

go2rtc:
  streams:
    camera_one:
      - rtsp://user:pass@192.168.XX.X:554/Streaming/Channels/101/
    camera_two:
      - rtsp://user:pass@192.168.XX.X:554/Streaming/Channels/101/
```

</details>

<ComponentTroubleshooting meta={ComponentMetadata} />
